// Copyright 2025 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Code generated by sidekick. DO NOT EDIT.

#![allow(rustdoc::redundant_explicit_links)]
#![allow(rustdoc::broken_intra_doc_links)]
#![no_implicit_prelude]
extern crate async_trait;
extern crate bytes;
extern crate gax;
extern crate gaxi;
extern crate lazy_static;
extern crate reqwest;
extern crate serde;
extern crate serde_json;
extern crate serde_with;
extern crate std;
extern crate tracing;
extern crate wkt;

mod debug;
mod deserialize;
mod serialize;

/// A running instance of a
/// [Workflow](/workflows/docs/reference/rest/v1/projects.locations.workflows).
#[derive(Clone, Default, PartialEq)]
#[non_exhaustive]
pub struct Execution {
    /// Output only. The resource name of the execution.
    /// Format:
    /// projects/{project}/locations/{location}/workflows/{workflow}/executions/{execution}
    pub name: std::string::String,

    /// Output only. Marks the beginning of execution.
    pub start_time: std::option::Option<wkt::Timestamp>,

    /// Output only. Marks the end of execution, successful or not.
    pub end_time: std::option::Option<wkt::Timestamp>,

    /// Output only. Measures the duration of the execution.
    pub duration: std::option::Option<wkt::Duration>,

    /// Output only. Current state of the execution.
    pub state: crate::model::execution::State,

    /// Input parameters of the execution represented as a JSON string.
    /// The size limit is 32KB.
    ///
    /// *Note*: If you are using the REST API directly to run your workflow, you
    /// must escape any JSON string value of `argument`. Example:
    /// `'{"argument":"{\"firstName\":\"FIRST\",\"lastName\":\"LAST\"}"}'`
    pub argument: std::string::String,

    /// Output only. Output of the execution represented as a JSON string. The
    /// value can only be present if the execution's state is `SUCCEEDED`.
    pub result: std::string::String,

    /// Output only. The error which caused the execution to finish prematurely.
    /// The value is only present if the execution's state is `FAILED`
    /// or `CANCELLED`.
    pub error: std::option::Option<crate::model::execution::Error>,

    /// Output only. Revision of the workflow this execution is using.
    pub workflow_revision_id: std::string::String,

    /// The call logging level associated to this execution.
    pub call_log_level: crate::model::execution::CallLogLevel,

    /// Output only. Status tracks the current steps and progress data of this
    /// execution.
    pub status: std::option::Option<crate::model::execution::Status>,

    /// Labels associated with this execution.
    /// Labels can contain at most 64 entries. Keys and values can be no longer
    /// than 63 characters and can only contain lowercase letters, numeric
    /// characters, underscores, and dashes. Label keys must start with a letter.
    /// International characters are allowed.
    /// By default, labels are inherited from the workflow but are overridden by
    /// any labels associated with the execution.
    pub labels: std::collections::HashMap<std::string::String, std::string::String>,

    /// Output only. Error regarding the state of the Execution resource. For
    /// example, this field will have error details if the execution data is
    /// unavailable due to revoked KMS key permissions.
    pub state_error: std::option::Option<crate::model::execution::StateError>,

    pub(crate) _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
}

impl Execution {
    pub fn new() -> Self {
        std::default::Default::default()
    }

    /// Sets the value of [name][crate::model::Execution::name].
    pub fn set_name<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
        self.name = v.into();
        self
    }

    /// Sets the value of [start_time][crate::model::Execution::start_time].
    pub fn set_start_time<T>(mut self, v: T) -> Self
    where
        T: std::convert::Into<wkt::Timestamp>,
    {
        self.start_time = std::option::Option::Some(v.into());
        self
    }

    /// Sets or clears the value of [start_time][crate::model::Execution::start_time].
    pub fn set_or_clear_start_time<T>(mut self, v: std::option::Option<T>) -> Self
    where
        T: std::convert::Into<wkt::Timestamp>,
    {
        self.start_time = v.map(|x| x.into());
        self
    }

    /// Sets the value of [end_time][crate::model::Execution::end_time].
    pub fn set_end_time<T>(mut self, v: T) -> Self
    where
        T: std::convert::Into<wkt::Timestamp>,
    {
        self.end_time = std::option::Option::Some(v.into());
        self
    }

    /// Sets or clears the value of [end_time][crate::model::Execution::end_time].
    pub fn set_or_clear_end_time<T>(mut self, v: std::option::Option<T>) -> Self
    where
        T: std::convert::Into<wkt::Timestamp>,
    {
        self.end_time = v.map(|x| x.into());
        self
    }

    /// Sets the value of [duration][crate::model::Execution::duration].
    pub fn set_duration<T>(mut self, v: T) -> Self
    where
        T: std::convert::Into<wkt::Duration>,
    {
        self.duration = std::option::Option::Some(v.into());
        self
    }

    /// Sets or clears the value of [duration][crate::model::Execution::duration].
    pub fn set_or_clear_duration<T>(mut self, v: std::option::Option<T>) -> Self
    where
        T: std::convert::Into<wkt::Duration>,
    {
        self.duration = v.map(|x| x.into());
        self
    }

    /// Sets the value of [state][crate::model::Execution::state].
    pub fn set_state<T: std::convert::Into<crate::model::execution::State>>(
        mut self,
        v: T,
    ) -> Self {
        self.state = v.into();
        self
    }

    /// Sets the value of [argument][crate::model::Execution::argument].
    pub fn set_argument<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
        self.argument = v.into();
        self
    }

    /// Sets the value of [result][crate::model::Execution::result].
    pub fn set_result<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
        self.result = v.into();
        self
    }

    /// Sets the value of [error][crate::model::Execution::error].
    pub fn set_error<T>(mut self, v: T) -> Self
    where
        T: std::convert::Into<crate::model::execution::Error>,
    {
        self.error = std::option::Option::Some(v.into());
        self
    }

    /// Sets or clears the value of [error][crate::model::Execution::error].
    pub fn set_or_clear_error<T>(mut self, v: std::option::Option<T>) -> Self
    where
        T: std::convert::Into<crate::model::execution::Error>,
    {
        self.error = v.map(|x| x.into());
        self
    }

    /// Sets the value of [workflow_revision_id][crate::model::Execution::workflow_revision_id].
    pub fn set_workflow_revision_id<T: std::convert::Into<std::string::String>>(
        mut self,
        v: T,
    ) -> Self {
        self.workflow_revision_id = v.into();
        self
    }

    /// Sets the value of [call_log_level][crate::model::Execution::call_log_level].
    pub fn set_call_log_level<T: std::convert::Into<crate::model::execution::CallLogLevel>>(
        mut self,
        v: T,
    ) -> Self {
        self.call_log_level = v.into();
        self
    }

    /// Sets the value of [status][crate::model::Execution::status].
    pub fn set_status<T>(mut self, v: T) -> Self
    where
        T: std::convert::Into<crate::model::execution::Status>,
    {
        self.status = std::option::Option::Some(v.into());
        self
    }

    /// Sets or clears the value of [status][crate::model::Execution::status].
    pub fn set_or_clear_status<T>(mut self, v: std::option::Option<T>) -> Self
    where
        T: std::convert::Into<crate::model::execution::Status>,
    {
        self.status = v.map(|x| x.into());
        self
    }

    /// Sets the value of [labels][crate::model::Execution::labels].
    pub fn set_labels<T, K, V>(mut self, v: T) -> Self
    where
        T: std::iter::IntoIterator<Item = (K, V)>,
        K: std::convert::Into<std::string::String>,
        V: std::convert::Into<std::string::String>,
    {
        use std::iter::Iterator;
        self.labels = v.into_iter().map(|(k, v)| (k.into(), v.into())).collect();
        self
    }

    /// Sets the value of [state_error][crate::model::Execution::state_error].
    pub fn set_state_error<T>(mut self, v: T) -> Self
    where
        T: std::convert::Into<crate::model::execution::StateError>,
    {
        self.state_error = std::option::Option::Some(v.into());
        self
    }

    /// Sets or clears the value of [state_error][crate::model::Execution::state_error].
    pub fn set_or_clear_state_error<T>(mut self, v: std::option::Option<T>) -> Self
    where
        T: std::convert::Into<crate::model::execution::StateError>,
    {
        self.state_error = v.map(|x| x.into());
        self
    }
}

impl wkt::message::Message for Execution {
    fn typename() -> &'static str {
        "type.googleapis.com/google.cloud.workflows.executions.v1.Execution"
    }
}

/// Defines additional types related to [Execution].
pub mod execution {
    #[allow(unused_imports)]
    use super::*;

    /// A single stack element (frame) where an error occurred.
    #[derive(Clone, Default, PartialEq)]
    #[non_exhaustive]
    pub struct StackTraceElement {
        /// The step the error occurred at.
        pub step: std::string::String,

        /// The routine where the error occurred.
        pub routine: std::string::String,

        /// The source position information of the stack trace element.
        pub position: std::option::Option<crate::model::execution::stack_trace_element::Position>,

        pub(crate) _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
    }

    impl StackTraceElement {
        pub fn new() -> Self {
            std::default::Default::default()
        }

        /// Sets the value of [step][crate::model::execution::StackTraceElement::step].
        pub fn set_step<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
            self.step = v.into();
            self
        }

        /// Sets the value of [routine][crate::model::execution::StackTraceElement::routine].
        pub fn set_routine<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
            self.routine = v.into();
            self
        }

        /// Sets the value of [position][crate::model::execution::StackTraceElement::position].
        pub fn set_position<T>(mut self, v: T) -> Self
        where
            T: std::convert::Into<crate::model::execution::stack_trace_element::Position>,
        {
            self.position = std::option::Option::Some(v.into());
            self
        }

        /// Sets or clears the value of [position][crate::model::execution::StackTraceElement::position].
        pub fn set_or_clear_position<T>(mut self, v: std::option::Option<T>) -> Self
        where
            T: std::convert::Into<crate::model::execution::stack_trace_element::Position>,
        {
            self.position = v.map(|x| x.into());
            self
        }
    }

    impl wkt::message::Message for StackTraceElement {
        fn typename() -> &'static str {
            "type.googleapis.com/google.cloud.workflows.executions.v1.Execution.StackTraceElement"
        }
    }

    /// Defines additional types related to [StackTraceElement].
    pub mod stack_trace_element {
        #[allow(unused_imports)]
        use super::*;

        /// Position contains source position information about the stack trace
        /// element such as line number, column number and length of the code block
        /// in bytes.
        #[derive(Clone, Default, PartialEq)]
        #[non_exhaustive]
        pub struct Position {
            /// The source code line number the current instruction was generated from.
            pub line: i64,

            /// The source code column position (of the line) the current instruction
            /// was generated from.
            pub column: i64,

            /// The number of bytes of source code making up this stack trace element.
            pub length: i64,

            pub(crate) _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
        }

        impl Position {
            pub fn new() -> Self {
                std::default::Default::default()
            }

            /// Sets the value of [line][crate::model::execution::stack_trace_element::Position::line].
            pub fn set_line<T: std::convert::Into<i64>>(mut self, v: T) -> Self {
                self.line = v.into();
                self
            }

            /// Sets the value of [column][crate::model::execution::stack_trace_element::Position::column].
            pub fn set_column<T: std::convert::Into<i64>>(mut self, v: T) -> Self {
                self.column = v.into();
                self
            }

            /// Sets the value of [length][crate::model::execution::stack_trace_element::Position::length].
            pub fn set_length<T: std::convert::Into<i64>>(mut self, v: T) -> Self {
                self.length = v.into();
                self
            }
        }

        impl wkt::message::Message for Position {
            fn typename() -> &'static str {
                "type.googleapis.com/google.cloud.workflows.executions.v1.Execution.StackTraceElement.Position"
            }
        }
    }

    /// A collection of stack elements (frames) where an error occurred.
    #[derive(Clone, Default, PartialEq)]
    #[non_exhaustive]
    pub struct StackTrace {
        /// An array of stack elements.
        pub elements: std::vec::Vec<crate::model::execution::StackTraceElement>,

        pub(crate) _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
    }

    impl StackTrace {
        pub fn new() -> Self {
            std::default::Default::default()
        }

        /// Sets the value of [elements][crate::model::execution::StackTrace::elements].
        pub fn set_elements<T, V>(mut self, v: T) -> Self
        where
            T: std::iter::IntoIterator<Item = V>,
            V: std::convert::Into<crate::model::execution::StackTraceElement>,
        {
            use std::iter::Iterator;
            self.elements = v.into_iter().map(|i| i.into()).collect();
            self
        }
    }

    impl wkt::message::Message for StackTrace {
        fn typename() -> &'static str {
            "type.googleapis.com/google.cloud.workflows.executions.v1.Execution.StackTrace"
        }
    }

    /// Error describes why the execution was abnormally terminated.
    #[derive(Clone, Default, PartialEq)]
    #[non_exhaustive]
    pub struct Error {
        /// Error message and data returned represented as a JSON string.
        pub payload: std::string::String,

        /// Human-readable stack trace string.
        pub context: std::string::String,

        /// Stack trace with detailed information of where error was generated.
        pub stack_trace: std::option::Option<crate::model::execution::StackTrace>,

        pub(crate) _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
    }

    impl Error {
        pub fn new() -> Self {
            std::default::Default::default()
        }

        /// Sets the value of [payload][crate::model::execution::Error::payload].
        pub fn set_payload<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
            self.payload = v.into();
            self
        }

        /// Sets the value of [context][crate::model::execution::Error::context].
        pub fn set_context<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
            self.context = v.into();
            self
        }

        /// Sets the value of [stack_trace][crate::model::execution::Error::stack_trace].
        pub fn set_stack_trace<T>(mut self, v: T) -> Self
        where
            T: std::convert::Into<crate::model::execution::StackTrace>,
        {
            self.stack_trace = std::option::Option::Some(v.into());
            self
        }

        /// Sets or clears the value of [stack_trace][crate::model::execution::Error::stack_trace].
        pub fn set_or_clear_stack_trace<T>(mut self, v: std::option::Option<T>) -> Self
        where
            T: std::convert::Into<crate::model::execution::StackTrace>,
        {
            self.stack_trace = v.map(|x| x.into());
            self
        }
    }

    impl wkt::message::Message for Error {
        fn typename() -> &'static str {
            "type.googleapis.com/google.cloud.workflows.executions.v1.Execution.Error"
        }
    }

    /// Represents the current status of this execution.
    #[derive(Clone, Default, PartialEq)]
    #[non_exhaustive]
    pub struct Status {
        /// A list of currently executing or last executed step names for the
        /// workflow execution currently running. If the workflow has succeeded or
        /// failed, this is the last attempted or executed step. Presently, if the
        /// current step is inside a subworkflow, the list only includes that step.
        /// In the future, the list will contain items for each step in the call
        /// stack, starting with the outermost step in the `main` subworkflow, and
        /// ending with the most deeply nested step.
        pub current_steps: std::vec::Vec<crate::model::execution::status::Step>,

        pub(crate) _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
    }

    impl Status {
        pub fn new() -> Self {
            std::default::Default::default()
        }

        /// Sets the value of [current_steps][crate::model::execution::Status::current_steps].
        pub fn set_current_steps<T, V>(mut self, v: T) -> Self
        where
            T: std::iter::IntoIterator<Item = V>,
            V: std::convert::Into<crate::model::execution::status::Step>,
        {
            use std::iter::Iterator;
            self.current_steps = v.into_iter().map(|i| i.into()).collect();
            self
        }
    }

    impl wkt::message::Message for Status {
        fn typename() -> &'static str {
            "type.googleapis.com/google.cloud.workflows.executions.v1.Execution.Status"
        }
    }

    /// Defines additional types related to [Status].
    pub mod status {
        #[allow(unused_imports)]
        use super::*;

        /// Represents a step of the workflow this execution is running.
        #[derive(Clone, Default, PartialEq)]
        #[non_exhaustive]
        pub struct Step {
            /// Name of a routine within the workflow.
            pub routine: std::string::String,

            /// Name of a step within the routine.
            pub step: std::string::String,

            pub(crate) _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
        }

        impl Step {
            pub fn new() -> Self {
                std::default::Default::default()
            }

            /// Sets the value of [routine][crate::model::execution::status::Step::routine].
            pub fn set_routine<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
                self.routine = v.into();
                self
            }

            /// Sets the value of [step][crate::model::execution::status::Step::step].
            pub fn set_step<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
                self.step = v.into();
                self
            }
        }

        impl wkt::message::Message for Step {
            fn typename() -> &'static str {
                "type.googleapis.com/google.cloud.workflows.executions.v1.Execution.Status.Step"
            }
        }
    }

    /// Describes an error related to the current state of the Execution resource.
    #[derive(Clone, Default, PartialEq)]
    #[non_exhaustive]
    pub struct StateError {
        /// Provides specifics about the error.
        pub details: std::string::String,

        /// The type of this state error.
        pub r#type: crate::model::execution::state_error::Type,

        pub(crate) _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
    }

    impl StateError {
        pub fn new() -> Self {
            std::default::Default::default()
        }

        /// Sets the value of [details][crate::model::execution::StateError::details].
        pub fn set_details<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
            self.details = v.into();
            self
        }

        /// Sets the value of [r#type][crate::model::execution::StateError::type].
        pub fn set_type<T: std::convert::Into<crate::model::execution::state_error::Type>>(
            mut self,
            v: T,
        ) -> Self {
            self.r#type = v.into();
            self
        }
    }

    impl wkt::message::Message for StateError {
        fn typename() -> &'static str {
            "type.googleapis.com/google.cloud.workflows.executions.v1.Execution.StateError"
        }
    }

    /// Defines additional types related to [StateError].
    pub mod state_error {
        #[allow(unused_imports)]
        use super::*;

        /// Describes the possible types of a state error.
        ///
        /// # Working with unknown values
        ///
        /// This enum is defined as `#[non_exhaustive]` because Google Cloud may add
        /// additional enum variants at any time. Adding new variants is not considered
        /// a breaking change. Applications should write their code in anticipation of:
        ///
        /// - New values appearing in future releases of the client library, **and**
        /// - New values received dynamically, without application changes.
        ///
        /// Please consult the [Working with enums] section in the user guide for some
        /// guidelines.
        ///
        /// [Working with enums]: https://google-cloud-rust.github.io/working_with_enums.html
        #[derive(Clone, Debug, PartialEq)]
        #[non_exhaustive]
        pub enum Type {
            /// No type specified.
            Unspecified,
            /// Caused by an issue with KMS.
            KmsError,
            /// If set, the enum was initialized with an unknown value.
            ///
            /// Applications can examine the value using [Type::value] or
            /// [Type::name].
            UnknownValue(r#type::UnknownValue),
        }

        #[doc(hidden)]
        pub mod r#type {
            #[allow(unused_imports)]
            use super::*;
            #[derive(Clone, Debug, PartialEq)]
            pub struct UnknownValue(pub(crate) wkt::internal::UnknownEnumValue);
        }

        impl Type {
            /// Gets the enum value.
            ///
            /// Returns `None` if the enum contains an unknown value deserialized from
            /// the string representation of enums.
            pub fn value(&self) -> std::option::Option<i32> {
                match self {
                    Self::Unspecified => std::option::Option::Some(0),
                    Self::KmsError => std::option::Option::Some(1),
                    Self::UnknownValue(u) => u.0.value(),
                }
            }

            /// Gets the enum value as a string.
            ///
            /// Returns `None` if the enum contains an unknown value deserialized from
            /// the integer representation of enums.
            pub fn name(&self) -> std::option::Option<&str> {
                match self {
                    Self::Unspecified => std::option::Option::Some("TYPE_UNSPECIFIED"),
                    Self::KmsError => std::option::Option::Some("KMS_ERROR"),
                    Self::UnknownValue(u) => u.0.name(),
                }
            }
        }

        impl std::default::Default for Type {
            fn default() -> Self {
                use std::convert::From;
                Self::from(0)
            }
        }

        impl std::fmt::Display for Type {
            fn fmt(
                &self,
                f: &mut std::fmt::Formatter<'_>,
            ) -> std::result::Result<(), std::fmt::Error> {
                wkt::internal::display_enum(f, self.name(), self.value())
            }
        }

        impl std::convert::From<i32> for Type {
            fn from(value: i32) -> Self {
                match value {
                    0 => Self::Unspecified,
                    1 => Self::KmsError,
                    _ => Self::UnknownValue(r#type::UnknownValue(
                        wkt::internal::UnknownEnumValue::Integer(value),
                    )),
                }
            }
        }

        impl std::convert::From<&str> for Type {
            fn from(value: &str) -> Self {
                use std::string::ToString;
                match value {
                    "TYPE_UNSPECIFIED" => Self::Unspecified,
                    "KMS_ERROR" => Self::KmsError,
                    _ => Self::UnknownValue(r#type::UnknownValue(
                        wkt::internal::UnknownEnumValue::String(value.to_string()),
                    )),
                }
            }
        }

        impl serde::ser::Serialize for Type {
            fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
            where
                S: serde::Serializer,
            {
                match self {
                    Self::Unspecified => serializer.serialize_i32(0),
                    Self::KmsError => serializer.serialize_i32(1),
                    Self::UnknownValue(u) => u.0.serialize(serializer),
                }
            }
        }

        impl<'de> serde::de::Deserialize<'de> for Type {
            fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
            where
                D: serde::Deserializer<'de>,
            {
                deserializer.deserialize_any(wkt::internal::EnumVisitor::<Type>::new(
                    ".google.cloud.workflows.executions.v1.Execution.StateError.Type",
                ))
            }
        }
    }

    /// Describes the current state of the execution. More states might be added
    /// in the future.
    ///
    /// # Working with unknown values
    ///
    /// This enum is defined as `#[non_exhaustive]` because Google Cloud may add
    /// additional enum variants at any time. Adding new variants is not considered
    /// a breaking change. Applications should write their code in anticipation of:
    ///
    /// - New values appearing in future releases of the client library, **and**
    /// - New values received dynamically, without application changes.
    ///
    /// Please consult the [Working with enums] section in the user guide for some
    /// guidelines.
    ///
    /// [Working with enums]: https://google-cloud-rust.github.io/working_with_enums.html
    #[derive(Clone, Debug, PartialEq)]
    #[non_exhaustive]
    pub enum State {
        /// Invalid state.
        Unspecified,
        /// The execution is in progress.
        Active,
        /// The execution finished successfully.
        Succeeded,
        /// The execution failed with an error.
        Failed,
        /// The execution was stopped intentionally.
        Cancelled,
        /// Execution data is unavailable. See the `state_error` field.
        Unavailable,
        /// Request has been placed in the backlog for processing at a later time.
        Queued,
        /// If set, the enum was initialized with an unknown value.
        ///
        /// Applications can examine the value using [State::value] or
        /// [State::name].
        UnknownValue(state::UnknownValue),
    }

    #[doc(hidden)]
    pub mod state {
        #[allow(unused_imports)]
        use super::*;
        #[derive(Clone, Debug, PartialEq)]
        pub struct UnknownValue(pub(crate) wkt::internal::UnknownEnumValue);
    }

    impl State {
        /// Gets the enum value.
        ///
        /// Returns `None` if the enum contains an unknown value deserialized from
        /// the string representation of enums.
        pub fn value(&self) -> std::option::Option<i32> {
            match self {
                Self::Unspecified => std::option::Option::Some(0),
                Self::Active => std::option::Option::Some(1),
                Self::Succeeded => std::option::Option::Some(2),
                Self::Failed => std::option::Option::Some(3),
                Self::Cancelled => std::option::Option::Some(4),
                Self::Unavailable => std::option::Option::Some(5),
                Self::Queued => std::option::Option::Some(6),
                Self::UnknownValue(u) => u.0.value(),
            }
        }

        /// Gets the enum value as a string.
        ///
        /// Returns `None` if the enum contains an unknown value deserialized from
        /// the integer representation of enums.
        pub fn name(&self) -> std::option::Option<&str> {
            match self {
                Self::Unspecified => std::option::Option::Some("STATE_UNSPECIFIED"),
                Self::Active => std::option::Option::Some("ACTIVE"),
                Self::Succeeded => std::option::Option::Some("SUCCEEDED"),
                Self::Failed => std::option::Option::Some("FAILED"),
                Self::Cancelled => std::option::Option::Some("CANCELLED"),
                Self::Unavailable => std::option::Option::Some("UNAVAILABLE"),
                Self::Queued => std::option::Option::Some("QUEUED"),
                Self::UnknownValue(u) => u.0.name(),
            }
        }
    }

    impl std::default::Default for State {
        fn default() -> Self {
            use std::convert::From;
            Self::from(0)
        }
    }

    impl std::fmt::Display for State {
        fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::result::Result<(), std::fmt::Error> {
            wkt::internal::display_enum(f, self.name(), self.value())
        }
    }

    impl std::convert::From<i32> for State {
        fn from(value: i32) -> Self {
            match value {
                0 => Self::Unspecified,
                1 => Self::Active,
                2 => Self::Succeeded,
                3 => Self::Failed,
                4 => Self::Cancelled,
                5 => Self::Unavailable,
                6 => Self::Queued,
                _ => Self::UnknownValue(state::UnknownValue(
                    wkt::internal::UnknownEnumValue::Integer(value),
                )),
            }
        }
    }

    impl std::convert::From<&str> for State {
        fn from(value: &str) -> Self {
            use std::string::ToString;
            match value {
                "STATE_UNSPECIFIED" => Self::Unspecified,
                "ACTIVE" => Self::Active,
                "SUCCEEDED" => Self::Succeeded,
                "FAILED" => Self::Failed,
                "CANCELLED" => Self::Cancelled,
                "UNAVAILABLE" => Self::Unavailable,
                "QUEUED" => Self::Queued,
                _ => Self::UnknownValue(state::UnknownValue(
                    wkt::internal::UnknownEnumValue::String(value.to_string()),
                )),
            }
        }
    }

    impl serde::ser::Serialize for State {
        fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
        where
            S: serde::Serializer,
        {
            match self {
                Self::Unspecified => serializer.serialize_i32(0),
                Self::Active => serializer.serialize_i32(1),
                Self::Succeeded => serializer.serialize_i32(2),
                Self::Failed => serializer.serialize_i32(3),
                Self::Cancelled => serializer.serialize_i32(4),
                Self::Unavailable => serializer.serialize_i32(5),
                Self::Queued => serializer.serialize_i32(6),
                Self::UnknownValue(u) => u.0.serialize(serializer),
            }
        }
    }

    impl<'de> serde::de::Deserialize<'de> for State {
        fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
        where
            D: serde::Deserializer<'de>,
        {
            deserializer.deserialize_any(wkt::internal::EnumVisitor::<State>::new(
                ".google.cloud.workflows.executions.v1.Execution.State",
            ))
        }
    }

    /// Describes the level of platform logging to apply to calls and call
    /// responses during workflow executions.
    ///
    /// # Working with unknown values
    ///
    /// This enum is defined as `#[non_exhaustive]` because Google Cloud may add
    /// additional enum variants at any time. Adding new variants is not considered
    /// a breaking change. Applications should write their code in anticipation of:
    ///
    /// - New values appearing in future releases of the client library, **and**
    /// - New values received dynamically, without application changes.
    ///
    /// Please consult the [Working with enums] section in the user guide for some
    /// guidelines.
    ///
    /// [Working with enums]: https://google-cloud-rust.github.io/working_with_enums.html
    #[derive(Clone, Debug, PartialEq)]
    #[non_exhaustive]
    pub enum CallLogLevel {
        /// No call logging level specified.
        Unspecified,
        /// Log all call steps within workflows, all call returns, and all exceptions
        /// raised.
        LogAllCalls,
        /// Log only exceptions that are raised from call steps within workflows.
        LogErrorsOnly,
        /// Explicitly log nothing.
        LogNone,
        /// If set, the enum was initialized with an unknown value.
        ///
        /// Applications can examine the value using [CallLogLevel::value] or
        /// [CallLogLevel::name].
        UnknownValue(call_log_level::UnknownValue),
    }

    #[doc(hidden)]
    pub mod call_log_level {
        #[allow(unused_imports)]
        use super::*;
        #[derive(Clone, Debug, PartialEq)]
        pub struct UnknownValue(pub(crate) wkt::internal::UnknownEnumValue);
    }

    impl CallLogLevel {
        /// Gets the enum value.
        ///
        /// Returns `None` if the enum contains an unknown value deserialized from
        /// the string representation of enums.
        pub fn value(&self) -> std::option::Option<i32> {
            match self {
                Self::Unspecified => std::option::Option::Some(0),
                Self::LogAllCalls => std::option::Option::Some(1),
                Self::LogErrorsOnly => std::option::Option::Some(2),
                Self::LogNone => std::option::Option::Some(3),
                Self::UnknownValue(u) => u.0.value(),
            }
        }

        /// Gets the enum value as a string.
        ///
        /// Returns `None` if the enum contains an unknown value deserialized from
        /// the integer representation of enums.
        pub fn name(&self) -> std::option::Option<&str> {
            match self {
                Self::Unspecified => std::option::Option::Some("CALL_LOG_LEVEL_UNSPECIFIED"),
                Self::LogAllCalls => std::option::Option::Some("LOG_ALL_CALLS"),
                Self::LogErrorsOnly => std::option::Option::Some("LOG_ERRORS_ONLY"),
                Self::LogNone => std::option::Option::Some("LOG_NONE"),
                Self::UnknownValue(u) => u.0.name(),
            }
        }
    }

    impl std::default::Default for CallLogLevel {
        fn default() -> Self {
            use std::convert::From;
            Self::from(0)
        }
    }

    impl std::fmt::Display for CallLogLevel {
        fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::result::Result<(), std::fmt::Error> {
            wkt::internal::display_enum(f, self.name(), self.value())
        }
    }

    impl std::convert::From<i32> for CallLogLevel {
        fn from(value: i32) -> Self {
            match value {
                0 => Self::Unspecified,
                1 => Self::LogAllCalls,
                2 => Self::LogErrorsOnly,
                3 => Self::LogNone,
                _ => Self::UnknownValue(call_log_level::UnknownValue(
                    wkt::internal::UnknownEnumValue::Integer(value),
                )),
            }
        }
    }

    impl std::convert::From<&str> for CallLogLevel {
        fn from(value: &str) -> Self {
            use std::string::ToString;
            match value {
                "CALL_LOG_LEVEL_UNSPECIFIED" => Self::Unspecified,
                "LOG_ALL_CALLS" => Self::LogAllCalls,
                "LOG_ERRORS_ONLY" => Self::LogErrorsOnly,
                "LOG_NONE" => Self::LogNone,
                _ => Self::UnknownValue(call_log_level::UnknownValue(
                    wkt::internal::UnknownEnumValue::String(value.to_string()),
                )),
            }
        }
    }

    impl serde::ser::Serialize for CallLogLevel {
        fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
        where
            S: serde::Serializer,
        {
            match self {
                Self::Unspecified => serializer.serialize_i32(0),
                Self::LogAllCalls => serializer.serialize_i32(1),
                Self::LogErrorsOnly => serializer.serialize_i32(2),
                Self::LogNone => serializer.serialize_i32(3),
                Self::UnknownValue(u) => u.0.serialize(serializer),
            }
        }
    }

    impl<'de> serde::de::Deserialize<'de> for CallLogLevel {
        fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
        where
            D: serde::Deserializer<'de>,
        {
            deserializer.deserialize_any(wkt::internal::EnumVisitor::<CallLogLevel>::new(
                ".google.cloud.workflows.executions.v1.Execution.CallLogLevel",
            ))
        }
    }
}

/// Request for the
/// [ListExecutions][]
/// method.
#[derive(Clone, Default, PartialEq)]
#[non_exhaustive]
pub struct ListExecutionsRequest {
    /// Required. Name of the workflow for which the executions should be listed.
    /// Format: projects/{project}/locations/{location}/workflows/{workflow}
    pub parent: std::string::String,

    /// Maximum number of executions to return per call.
    /// Max supported value depends on the selected Execution view: it's 1000 for
    /// BASIC and 100 for FULL. The default value used if the field is not
    /// specified is 100, regardless of the selected view. Values greater than
    /// the max value will be coerced down to it.
    pub page_size: i32,

    /// A page token, received from a previous `ListExecutions` call.
    /// Provide this to retrieve the subsequent page.
    ///
    /// When paginating, all other parameters provided to `ListExecutions` must
    /// match the call that provided the page token.
    ///
    /// Note that pagination is applied to dynamic data. The list of executions
    /// returned can change between page requests.
    pub page_token: std::string::String,

    /// Optional. A view defining which fields should be filled in the returned
    /// executions. The API will default to the BASIC view.
    pub view: crate::model::ExecutionView,

    /// Optional. Filters applied to the [Executions.ListExecutions] results.
    /// The following fields are supported for filtering:
    /// executionID, state, startTime, endTime, duration, workflowRevisionID,
    /// stepName, and label.
    pub filter: std::string::String,

    /// Optional. The ordering applied to the [Executions.ListExecutions] results.
    /// By default the ordering is based on descending start time.
    /// The following fields are supported for order by:
    /// executionID, startTime, endTime, duration, state, and workflowRevisionID.
    pub order_by: std::string::String,

    pub(crate) _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
}

impl ListExecutionsRequest {
    pub fn new() -> Self {
        std::default::Default::default()
    }

    /// Sets the value of [parent][crate::model::ListExecutionsRequest::parent].
    pub fn set_parent<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
        self.parent = v.into();
        self
    }

    /// Sets the value of [page_size][crate::model::ListExecutionsRequest::page_size].
    pub fn set_page_size<T: std::convert::Into<i32>>(mut self, v: T) -> Self {
        self.page_size = v.into();
        self
    }

    /// Sets the value of [page_token][crate::model::ListExecutionsRequest::page_token].
    pub fn set_page_token<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
        self.page_token = v.into();
        self
    }

    /// Sets the value of [view][crate::model::ListExecutionsRequest::view].
    pub fn set_view<T: std::convert::Into<crate::model::ExecutionView>>(mut self, v: T) -> Self {
        self.view = v.into();
        self
    }

    /// Sets the value of [filter][crate::model::ListExecutionsRequest::filter].
    pub fn set_filter<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
        self.filter = v.into();
        self
    }

    /// Sets the value of [order_by][crate::model::ListExecutionsRequest::order_by].
    pub fn set_order_by<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
        self.order_by = v.into();
        self
    }
}

impl wkt::message::Message for ListExecutionsRequest {
    fn typename() -> &'static str {
        "type.googleapis.com/google.cloud.workflows.executions.v1.ListExecutionsRequest"
    }
}

/// Response for the
/// [ListExecutions][google.cloud.workflows.executions.v1.Executions.ListExecutions]
/// method.
///
/// [google.cloud.workflows.executions.v1.Executions.ListExecutions]: crate::client::Executions::list_executions
#[derive(Clone, Default, PartialEq)]
#[non_exhaustive]
pub struct ListExecutionsResponse {
    /// The executions which match the request.
    pub executions: std::vec::Vec<crate::model::Execution>,

    /// A token, which can be sent as `page_token` to retrieve the next page.
    /// If this field is omitted, there are no subsequent pages.
    pub next_page_token: std::string::String,

    pub(crate) _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
}

impl ListExecutionsResponse {
    pub fn new() -> Self {
        std::default::Default::default()
    }

    /// Sets the value of [executions][crate::model::ListExecutionsResponse::executions].
    pub fn set_executions<T, V>(mut self, v: T) -> Self
    where
        T: std::iter::IntoIterator<Item = V>,
        V: std::convert::Into<crate::model::Execution>,
    {
        use std::iter::Iterator;
        self.executions = v.into_iter().map(|i| i.into()).collect();
        self
    }

    /// Sets the value of [next_page_token][crate::model::ListExecutionsResponse::next_page_token].
    pub fn set_next_page_token<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
        self.next_page_token = v.into();
        self
    }
}

impl wkt::message::Message for ListExecutionsResponse {
    fn typename() -> &'static str {
        "type.googleapis.com/google.cloud.workflows.executions.v1.ListExecutionsResponse"
    }
}

#[doc(hidden)]
impl gax::paginator::internal::PageableResponse for ListExecutionsResponse {
    type PageItem = crate::model::Execution;

    fn items(self) -> std::vec::Vec<Self::PageItem> {
        self.executions
    }

    fn next_page_token(&self) -> std::string::String {
        use std::clone::Clone;
        self.next_page_token.clone()
    }
}

/// Request for the
/// [CreateExecution][google.cloud.workflows.executions.v1.Executions.CreateExecution]
/// method.
///
/// [google.cloud.workflows.executions.v1.Executions.CreateExecution]: crate::client::Executions::create_execution
#[derive(Clone, Default, PartialEq)]
#[non_exhaustive]
pub struct CreateExecutionRequest {
    /// Required. Name of the workflow for which an execution should be created.
    /// Format: projects/{project}/locations/{location}/workflows/{workflow}
    /// The latest revision of the workflow will be used.
    pub parent: std::string::String,

    /// Required. Execution to be created.
    pub execution: std::option::Option<crate::model::Execution>,

    pub(crate) _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
}

impl CreateExecutionRequest {
    pub fn new() -> Self {
        std::default::Default::default()
    }

    /// Sets the value of [parent][crate::model::CreateExecutionRequest::parent].
    pub fn set_parent<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
        self.parent = v.into();
        self
    }

    /// Sets the value of [execution][crate::model::CreateExecutionRequest::execution].
    pub fn set_execution<T>(mut self, v: T) -> Self
    where
        T: std::convert::Into<crate::model::Execution>,
    {
        self.execution = std::option::Option::Some(v.into());
        self
    }

    /// Sets or clears the value of [execution][crate::model::CreateExecutionRequest::execution].
    pub fn set_or_clear_execution<T>(mut self, v: std::option::Option<T>) -> Self
    where
        T: std::convert::Into<crate::model::Execution>,
    {
        self.execution = v.map(|x| x.into());
        self
    }
}

impl wkt::message::Message for CreateExecutionRequest {
    fn typename() -> &'static str {
        "type.googleapis.com/google.cloud.workflows.executions.v1.CreateExecutionRequest"
    }
}

/// Request for the
/// [GetExecution][google.cloud.workflows.executions.v1.Executions.GetExecution]
/// method.
///
/// [google.cloud.workflows.executions.v1.Executions.GetExecution]: crate::client::Executions::get_execution
#[derive(Clone, Default, PartialEq)]
#[non_exhaustive]
pub struct GetExecutionRequest {
    /// Required. Name of the execution to be retrieved.
    /// Format:
    /// projects/{project}/locations/{location}/workflows/{workflow}/executions/{execution}
    pub name: std::string::String,

    /// Optional. A view defining which fields should be filled in the returned
    /// execution. The API will default to the FULL view.
    pub view: crate::model::ExecutionView,

    pub(crate) _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
}

impl GetExecutionRequest {
    pub fn new() -> Self {
        std::default::Default::default()
    }

    /// Sets the value of [name][crate::model::GetExecutionRequest::name].
    pub fn set_name<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
        self.name = v.into();
        self
    }

    /// Sets the value of [view][crate::model::GetExecutionRequest::view].
    pub fn set_view<T: std::convert::Into<crate::model::ExecutionView>>(mut self, v: T) -> Self {
        self.view = v.into();
        self
    }
}

impl wkt::message::Message for GetExecutionRequest {
    fn typename() -> &'static str {
        "type.googleapis.com/google.cloud.workflows.executions.v1.GetExecutionRequest"
    }
}

/// Request for the
/// [CancelExecution][google.cloud.workflows.executions.v1.Executions.CancelExecution]
/// method.
///
/// [google.cloud.workflows.executions.v1.Executions.CancelExecution]: crate::client::Executions::cancel_execution
#[derive(Clone, Default, PartialEq)]
#[non_exhaustive]
pub struct CancelExecutionRequest {
    /// Required. Name of the execution to be cancelled.
    /// Format:
    /// projects/{project}/locations/{location}/workflows/{workflow}/executions/{execution}
    pub name: std::string::String,

    pub(crate) _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
}

impl CancelExecutionRequest {
    pub fn new() -> Self {
        std::default::Default::default()
    }

    /// Sets the value of [name][crate::model::CancelExecutionRequest::name].
    pub fn set_name<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
        self.name = v.into();
        self
    }
}

impl wkt::message::Message for CancelExecutionRequest {
    fn typename() -> &'static str {
        "type.googleapis.com/google.cloud.workflows.executions.v1.CancelExecutionRequest"
    }
}

/// Defines possible views for execution resource.
///
/// # Working with unknown values
///
/// This enum is defined as `#[non_exhaustive]` because Google Cloud may add
/// additional enum variants at any time. Adding new variants is not considered
/// a breaking change. Applications should write their code in anticipation of:
///
/// - New values appearing in future releases of the client library, **and**
/// - New values received dynamically, without application changes.
///
/// Please consult the [Working with enums] section in the user guide for some
/// guidelines.
///
/// [Working with enums]: https://google-cloud-rust.github.io/working_with_enums.html
#[derive(Clone, Debug, PartialEq)]
#[non_exhaustive]
pub enum ExecutionView {
    /// The default / unset value.
    Unspecified,
    /// Includes only basic metadata about the execution.
    /// The following fields are returned: name, start_time, end_time, duration,
    /// state, and workflow_revision_id.
    Basic,
    /// Includes all data.
    Full,
    /// If set, the enum was initialized with an unknown value.
    ///
    /// Applications can examine the value using [ExecutionView::value] or
    /// [ExecutionView::name].
    UnknownValue(execution_view::UnknownValue),
}

#[doc(hidden)]
pub mod execution_view {
    #[allow(unused_imports)]
    use super::*;
    #[derive(Clone, Debug, PartialEq)]
    pub struct UnknownValue(pub(crate) wkt::internal::UnknownEnumValue);
}

impl ExecutionView {
    /// Gets the enum value.
    ///
    /// Returns `None` if the enum contains an unknown value deserialized from
    /// the string representation of enums.
    pub fn value(&self) -> std::option::Option<i32> {
        match self {
            Self::Unspecified => std::option::Option::Some(0),
            Self::Basic => std::option::Option::Some(1),
            Self::Full => std::option::Option::Some(2),
            Self::UnknownValue(u) => u.0.value(),
        }
    }

    /// Gets the enum value as a string.
    ///
    /// Returns `None` if the enum contains an unknown value deserialized from
    /// the integer representation of enums.
    pub fn name(&self) -> std::option::Option<&str> {
        match self {
            Self::Unspecified => std::option::Option::Some("EXECUTION_VIEW_UNSPECIFIED"),
            Self::Basic => std::option::Option::Some("BASIC"),
            Self::Full => std::option::Option::Some("FULL"),
            Self::UnknownValue(u) => u.0.name(),
        }
    }
}

impl std::default::Default for ExecutionView {
    fn default() -> Self {
        use std::convert::From;
        Self::from(0)
    }
}

impl std::fmt::Display for ExecutionView {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::result::Result<(), std::fmt::Error> {
        wkt::internal::display_enum(f, self.name(), self.value())
    }
}

impl std::convert::From<i32> for ExecutionView {
    fn from(value: i32) -> Self {
        match value {
            0 => Self::Unspecified,
            1 => Self::Basic,
            2 => Self::Full,
            _ => Self::UnknownValue(execution_view::UnknownValue(
                wkt::internal::UnknownEnumValue::Integer(value),
            )),
        }
    }
}

impl std::convert::From<&str> for ExecutionView {
    fn from(value: &str) -> Self {
        use std::string::ToString;
        match value {
            "EXECUTION_VIEW_UNSPECIFIED" => Self::Unspecified,
            "BASIC" => Self::Basic,
            "FULL" => Self::Full,
            _ => Self::UnknownValue(execution_view::UnknownValue(
                wkt::internal::UnknownEnumValue::String(value.to_string()),
            )),
        }
    }
}

impl serde::ser::Serialize for ExecutionView {
    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
    where
        S: serde::Serializer,
    {
        match self {
            Self::Unspecified => serializer.serialize_i32(0),
            Self::Basic => serializer.serialize_i32(1),
            Self::Full => serializer.serialize_i32(2),
            Self::UnknownValue(u) => u.0.serialize(serializer),
        }
    }
}

impl<'de> serde::de::Deserialize<'de> for ExecutionView {
    fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
    where
        D: serde::Deserializer<'de>,
    {
        deserializer.deserialize_any(wkt::internal::EnumVisitor::<ExecutionView>::new(
            ".google.cloud.workflows.executions.v1.ExecutionView",
        ))
    }
}
